// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

MainPage {
    id: container

    ListModel {
        id: scoreModel
    }

    Component {
        id: scoreDelegate
        Item {
            //anchors.verticalCenter: container.verticalCenter
            width:container.width; height: 50
            Text {
                anchors.leftMargin: 20
                anchors.left: parent.left;
                color: "white"
                font.pointSize: 15; style: Text.Outline; styleColor: "pink"
                text: name
            }
            Text {
                anchors.rightMargin: 20
                anchors.right: parent.right
                color: "white"
                font.pointSize: 15; style: Text.Outline; styleColor: "pink"
                text: score
            }
        }
    }

    ListView {
        anchors.fill: parent
        model: scoreModel
        delegate: scoreDelegate
    }

    function populateModel() {
        var db = openDatabaseSync("Lines98DB", "1.0", "Local Lines 98 SQL!", 1000000);
        db.transaction(
                    function(tx) {
                        // Create the database if it doesn't already exist
                        tx.executeSql('CREATE TABLE IF NOT EXISTS HighScore(name TEXT, score NUMBER)');

                        var rs = tx.executeSql('SELECT * FROM HighScore ORDER BY score DESC');
                        scoreModel.clear();
                        for(var i = 0; i < rs.rows.length; i++) {
                            scoreModel.append({"name":rs.rows.item(i).name, "score":rs.rows.item(i).score});
                            console.debug("name: "+rs.rows.item(i).name+"score:"+rs.rows.item(i).score);
                        }
                    }
                    )
    }
}
